//
//  TitleButton.swift
//  WBDemo
//
//  Created by Jin on 18/04/2018.
//  Copyright © 2018 com.baidu.123. All rights reserved.
//

import UIKit

class TitleButton: UIButton {

    //通过代码创建会调用
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        let userAccount = UserAccount.loadUserAccount()
        setTitle((userAccount?.screen_name)! + " ", for: .normal)
        setTitleColor(UIColor.darkGray, for: .normal)
        setImage(UIImage(named: "navigationbar_arrow_down"), for: .normal)
        setImage(UIImage(named: "navigationbar_arrow_up"), for: .selected)
        sizeToFit()
    }
    
    //通过SB或XIB创建会调用
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        titleLabel?.frame.origin.x = 0
        imageView?.frame.origin.x = titleLabel!.frame.width
    }

}
